package cn.tedu.service.impl;

import cn.tedu.mapper.StudentMapper;
import cn.tedu.pojo.Student;
import cn.tedu.pojo.User;
import cn.tedu.service.StudentService;
import cn.tedu.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;
    @Override
    public PageResult getStudentList(PageResult pageResult) {
        long total = studentMapper.findTotal();
        int size = pageResult.getPageSize();
        int start = (pageResult.getPageNum()-1) * size;
        String query = pageResult.getQuery();
        List<Student> userList = studentMapper.findStudentByPage(start,size,query);
        return pageResult.setTotal(total).setRows(userList);
    }

    @Override
    public void updateStudentById(Student student) {
        studentMapper.updateById(student);
    }

    @Override
    public void deleteStudentById(Integer id) {
        studentMapper.deleteById(id);
    }

    @Override
    public PageResult getXuejiList(PageResult pageResult) {
        long total = studentMapper.findTotal1();
        int size = pageResult.getPageSize();//条数  http://manage.jt.com/user/list没条件传进来查不到，报空指针
        int start = (pageResult.getPageNum()-1) * size;//起始位置
        String query = pageResult.getQuery();//查询条件
        List<Student> userList = studentMapper.findXuejiByPage(start,size,query);
        return pageResult.setTotal(total).setRows(userList);
    }
}
